//
//  FLLFindPasswordViewController.m
//  FLLGodOfCookery
//
//  Created by LL.F on 16/8/29.
//  Copyright © 2016年 LL.F. All rights reserved.
//

#import "FLLFindPasswordViewController.h"
#import "FLLMacro.h"
#import "AFNetworking.h"

@interface FLLFindPasswordViewController ()<UIGestureRecognizerDelegate>
@property (weak, nonatomic) IBOutlet UILabel *getVCAPTCHALabel;
@property (weak, nonatomic) IBOutlet UIImageView *CAPTCHAImageView;

@end

@implementation FLLFindPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    // 实现隐藏顶部navigationBar也有左滑返回的效果<2>
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    
    self.getVCAPTCHALabel.layer.borderColor = FLLOrangeColor.CGColor;
    _getVCAPTCHALabel.layer.borderWidth = 1;
    _getVCAPTCHALabel.layer.masksToBounds = YES;
    _getVCAPTCHALabel.layer.cornerRadius = 5.0f;

    
}
// 隐藏顶部 navigationBar
// 隐藏顶部 navigationBar后就不会有左滑返回的效果了
- (void)viewWillAppear:(BOOL)animated
{
    
    self.navigationController.navigationBarHidden = YES;
    // 实现隐藏顶部navigationBar也有左滑返回的效果<3>
    [self.navigationController.view sendSubviewToBack:self.navigationController.navigationBar];
    // 获取图形验证码
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    // 这行就是改变默认解析状态 使返回来的是Data类型数据 而不是JSON解析好的字典 在这里我自己进行JSON解析
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager GET:@"http://m.izhangchu.com/index/verify.html?sessid=%7B563de841-1f50-bb92-ad1a-f123de21496d%7D" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        self.CAPTCHAImageView.image = [UIImage imageWithData:responseObject];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
    }];

    
    
}
- (void)viewWillDisappear:(BOOL)animated
{
    
    self.navigationController.navigationBarHidden = NO;
    // 实现隐藏顶部navigationBar也有左滑返回的效果<4>
    [self.navigationController.view bringSubviewToFront:self.navigationController.navigationBar];
    
}

- (IBAction)didClickedBackButton:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)didClickedExchangeButton:(id)sender
{
    // 获取图形验证码
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    // 这行就是改变默认解析状态 使返回来的是Data类型数据 而不是JSON解析好的字典 在这里我自己进行JSON解析
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager GET:@"http://m.izhangchu.com/index/verify.html?sessid=%7B563de841-1f50-bb92-ad1a-f123de21496d%7D" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        self.CAPTCHAImageView.image = [UIImage imageWithData:responseObject];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
    }];

}
// 隐藏底部 tabBar
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
